package com.hellowx.controller;


import com.alibaba.fastjson.JSONObject;
import com.hellowx.entity.Product;
import com.hellowx.feignclient.ProductClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author MagicMushroom
 * @date 2021/7/4
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    public static final Logger logger = LoggerFactory.getLogger(CategoryController.class);

    @Resource
    private ProductClient productClient;

    @GetMapping
    public String category(){
        logger.info("category ok");
        String product = productClient.product();
        logger.info(product);
        return "category ok";
    }

    @GetMapping("/test")
    public String test(){
//        String ret = productClient.testQueryString(123, "lll");

//        String ret = productClient.testRestFull(321,"啦啦");

//        String ret = productClient.testJson(new Product(222,"asdad",1235));

//        String ret = productClient.testArray(new Integer[]{11,22,33,44});

//        String ret = productClient.testList(new Integer[]{11,22,33,44});

//        String ret = productClient.testObject(111,"asdad",545);

//        Product product = productClient.testReturnObject(12);

//        List<Product> productList = productClient.testReturnList(123);

        String s = productClient.testReturnMap(1, 2);

        JSONObject jsonObject = JSONObject.parseObject(s);

        logger.info(String.valueOf(jsonObject.get("total")));

        List<Product> productList = JSONObject.parseArray(jsonObject.get("list").toString(), Product.class);
        productList.forEach(item ->{
            logger.info(item.toString());
        });

        return s;
    }
}
